package com.examples.filedialog;

import java.io.FileWriter;
import java.io.IOException;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;

public class FileDialogSave {

  public static void main(String[] a) {
	Display d = Display.getDefault();  
    Shell s = new Shell(d);
    
    FileDialog fd = new FileDialog(s, SWT.SAVE);
    fd.setText("Save");
    fd.setFilterPath("C:/");
    String[] filterExt = {"*.txt","*.doc", ".rtf", "*.*"};
    fd.setFilterExtensions(filterExt);
    String selected = fd.open();
    
    try {
    	if(selected != null){
    		@SuppressWarnings("resource")
			FileWriter fileWriter = new FileWriter(selected);
    		fileWriter.write(selected);
    	}
	} catch (IOException e) {
		e.printStackTrace();
	}
    
  }
}
